package xgenerator.ui.swing;

import javax.swing.*;
import java.awt.*;

/**
 * <p>
 * Title：既然在GridBagConstraints对象中的约束条件哪么多，我们不妨可以自己定义一个类LayoutUtil，该类中包含两个静态方法add，如下所示
 * </p>
 * <p>
 * Description：
 * </p>
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * <p>
 * Company: liss
 * </p>
 * @author <a href="mailto:shushanlee@msn.com">liss</a>
 * @version 1.0
 * @see 
 * @since 1.0
 */
public class LayoutUtils {
	public static void add(Container container, int fill, int anchor, int weightx, int weighty, int x, int y, int width, int height, Component comp) {
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = fill;
		constraints.anchor = anchor;
		constraints.weightx = weightx;
		constraints.weighty = weighty;
		constraints.gridx = x;
		constraints.gridy = y;
		constraints.gridwidth = width;
		constraints.gridheight = height;
		container.add(comp, constraints);
	}

	public static void add(Container container, int fill, int anchor, int weightx, int weighty, int x, int y, int width, int height, Component comp, Insets insets) {
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.insets = insets;
		constraints.fill = fill;
		constraints.anchor = anchor;
		constraints.weightx = weightx;
		constraints.weighty = weighty;
		constraints.gridx = x;
		constraints.gridy = y;
		constraints.gridwidth = width;
		constraints.gridheight = height;
		container.add(comp, constraints);
	}
}